﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace BusinessLogic
{
    public class UpdateStatusCommand : BaseCommand<object>
    {

        public UpdateStatusCommand(string req_status,int reply_by, int id)
        {
            int TimeZoneDiff = Convert.ToInt32(ConfigurationManager.AppSettings["TimeZoneDiff"].ToString());

            SetQuery("UPDATE acm_tx SET [tx_status]=@tx_status,[change_request_status]=@change_request_status, [change_reply_date]=@change_reply_date,[change_reply_by]=@change_reply_by WHERE id=@id");

            cmd.Parameters.AddWithValue("tx_status", "ตอบรับคำขอแล้ว");
            cmd.Parameters.AddWithValue("change_request_status", req_status);
            cmd.Parameters.AddWithValue("change_reply_date", DateTime.Now.AddHours(TimeZoneDiff));
            cmd.Parameters.AddWithValue("change_reply_by", reply_by);
            cmd.Parameters.AddWithValue("id", id);
        }


        public UpdateStatusCommand(string selected, string status)
        {
            if (status == "จ่ายแล้ว")
            {
                SetQuery("UPDATE acm_tx SET [tx_status]=@tx_status, [approve_date]=@approve_date WHERE id in (" + selected + ")");
                cmd.Parameters.AddWithValue("approve_date", DateTime.Now);
            }
            else
            {
                SetQuery("UPDATE acm_tx SET [tx_status]=@tx_status, [approve_date]=null WHERE id in (" + selected + ")");
            }

            cmd.Parameters.AddWithValue("tx_status", status);
        }


        public override void Command()
        {
            Result = cmd.ExecuteNonQuery();
        }
    }
}
